﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rel.Expressions;

using System.Text.RegularExpressions;

namespace Rel
{
    class Program
    {
        static void Main(string[] args)
        {

            Rel.Expressions.RelGroup r = new Expressions.RelGroup();

            r.Starter.Literal("{").One().

               Or(new Rel.Expressions.RelGroup().Starter.
                    NoCharacterMatches("}").
                    ZeroOrMore().Parent,
                    new Rel.Expressions.
                        RelGroup().Starter.

                                Literal("\\").
                                One().
                                Literal("}").
                                One().Parent).
                                ZeroOrMore().
            Literal("}").One();

            var matches =
                Rel.Expressions.
                RelResultGroup.
                GetAllMatches("{test1} {test2} {test3} {Test4} {test5}", r);

            matches.ForEach(o =>
                {
                    Console.WriteLine("Pattern:");
                    Console.WriteLine(o.PatternMatched.Pattern);

                    o.Results.ForEach(o2 => Console.WriteLine(o2.piece.GroupName + ": " + o2.piece.Pattern + " = " + o2.Match));
                });



            Rel.Expressions.RelGroup testExtract =
                new Expressions.RelGroup().Starter.
                Literal("{").One().Extract("APiece", new Rel.Expressions.RelGroup().Starter.Or(new Rel.Expressions.RelGroup().Starter.
                    NoCharacterMatches("}").
                    ZeroOrMore().Parent,
                    new Rel.Expressions.
                        RelGroup().Starter.

                                Literal("\\").
                                One().
                                Literal("}").
                                One().Parent).
                                ZeroOrMore().Parent).One().Literal("}").One().Parent;

            var extractMatches = Rel.Expressions.RelResultGroup
                .GetAllExtracts("{test1} {test2} {test3} {Test4} {test5}", testExtract);


            string voidsrc = "public \r\nvoid TestCommand(int i, string jaja, float \r\nk, double o);\r\n private void \r\nhelloworld(string s);";

            
            RelGroup parameterinternal = new Expressions.RelGroup().Starter.WordCharacter().
                            OneOrMore().Whitespace().OneOrMore().WordCharacter().
                            OneOrMore().Parent;

            Rel.Expressions.RelGroup testcmdextract = new Expressions.RelGroup().Starter.
                ExtractCollection("modifierandcommand",
                new Expressions.RelGroup().Starter.NoCharacterMatches("(").
                OneOrMore().StartOfString().Parent
                        ,
                         new Expressions.RelGroup().Starter.
                            WordCharacter().OneOrMore().Parent).One().Parent;


            Console.WriteLine(testcmdextract.Pattern);

            var voidmatch = RelResultGroup.GetAllExtracts(voidsrc, testcmdextract);

            foreach (RelResultGroup aresultgroup in voidmatch)
            {
                Console.WriteLine(aresultgroup.PatternMatched);
                aresultgroup.Results.ForEach(o =>
                    {
                        Console.WriteLine(o.piece.Pattern + "=" + o.Match);
                       
                       if (o.ContainsCollection)
                       {
                           Console.WriteLine("Contains collection:");
                           
                           for (int x = 0; x < o.Collection.Count; x++)
                           {
                               Console.WriteLine(x.ToString() + ": " + o.Collection[x]);
                           }
                       }
                    });
            }

            Console.ReadLine();

        }
    }
}
